<template>
	<MyPage title="提现" :isback="true">
		<view slot="gBody">
			<!-- 活动 -->
			<view class="notice-box">
				<u-notice-bar type="warning" border-radius="20" :more-icon="true" :list="newsList" @click="$utils.navigateTo('/vip/index')"></u-notice-bar>
			</view>
			<!-- 提现 -->
			<u-form-item label="￥" label-width="80" :label-style="{'font-size':'60rpx'}" class="price-item"><u-input v-model="price" type="number" placeholder="金额" :focus="true" :trim="true" :clearable="false" :custom-style="{'font-size':'45rpx'}" @blur="moneyBlur" /></u-form-item>
			<view class="grey u-text-center">当前最多可提取 {{maxMoney}} 元</view>
			<view class="main">
				<!--
				<view class="page-card">
					<u-cell-item title="微信" :arrow="false" @click="type=1">
						<u-icon slot="icon" size="65" name="weixin-circle-fill" color="#2ab047" style="margin-right:20rpx"></u-icon>
						<u-icon slot="right-icon" size="38" name="checkmark-circle-fill" :color="type==1?'#eeb115':'#ddd'"></u-icon>
					</u-cell-item>
					<u-cell-item title="支付宝" :arrow="false" @click="type=2">
						<u-icon slot="icon" size="65" name="zhifubao-circle-fill" color="#1362ff" style="margin-right:20rpx"></u-icon>
						<u-icon slot="right-icon" size="38" name="checkmark-circle-fill" :color="type==2?'#eeb115':'#ddd'"></u-icon>
					</u-cell-item>
				</view>
				-->
				<view class="page-card">
					<u-cell-item title="真实姓名 : " :arrow="false">
						<u-input placeholder="请输入支付宝对应的真实姓名" :trim="true" v-model="xm" />
					</u-cell-item>
				</view>
				<view class="page-card">
					<u-cell-item title="支付宝账号 : " :arrow="false">
						<u-input placeholder="请输入您的支付宝账号" :trim="true" v-model="zfb" />
					</u-cell-item>
				</view>
				<u-button type="warning" shape="circle" class="btn" @click="btnSubmit">确定</u-button>
			</view>
		</view>
	</MyPage>
</template>		

<script>
import mixin from "@/libs/mixin.js";
import { getWalletInfo } from '@/api/wallet.js'
export default {
	mixins: [mixin],
	data() {
		return {
			newsList: [],
			price: '',
			type: '1',
			maxMoney: "0.00",
			zfb:'',
			xm:''
		}
	},
	onLoad(option) {
		if(!this.$store.state.app.token){
			this.$utils.redirectTo('/pages/login/login',{
				title:"登录",
				subTitle:"请先登录",
				btnValue:"请先登录",
				url:'/login/login'
			});
		}else{
			this.getData();
		} 
		// 获取金额
		this.price = option.money;
	},
	methods: {
		getData(){
			// 获取滚动数据
			uni.request({ 
				url: 'http://www.txzh.com.cn/api.php?app=Default&act=getCzje',  
				method: 'POST',
				header: {
					'Content-Type': 'application/x-www-form-urlencoded',
					'X-Requested-With': 'xmlhttprequest'
				}, 
				data:{token:this.$store.state.app.token,},
				success: res => {
					this.newsList = res.data.newsList;
				},   
				fail: () => {},  
				complete: () => {}  
			});
			//获取钱包数据
			getWalletInfo({token:this.$store.state.app.token}).then(res=>{
				this.maxMoney = res.money;
			}).catch(err=>{
				uni.showToast({
					title: err.msg,
					icon:'none'
				})
			});
		},
		// 文本框失焦校验
		moneyBlur(){
			if( !this.price ){
				this.price = '';
			}else if( this.price > this.maxMoney ){
				this.price = this.maxMoney;
			}
		},
		// 表单提交
		btnSubmit(){
			if(this.price<=0||this.price == ''){
				uni.showToast({
					title: '请正确填写提现金额',
					icon:'none'
				});
			}else if(this.zfb == ''){
				uni.showToast({
					title: '请正确填写您的支付账户',
					icon:'none'
				});
			}else if(this.xm == ''){
				uni.showToast({
					title: '请正确填写您的真实姓名',
					icon:'none'
				});
			}else{
				uni.request({
					url: 'http://www.txzh.com.cn/api.php?app=Default&act=Tixian',  
					method: 'POST',
					header: {
						'Content-Type': 'application/x-www-form-urlencoded', 
						'X-Requested-With': 'xmlhttprequest'
					},
					data:{
						token:this.$store.state.app.token,
						price:this.price,
						zfb:this.zfb
					},
					success: res => {
						console.log(res);
						if(res.data.list.err == 0){
							this.$utils.redirectTo('/common/success',{
								title:"提现成功！",
								//subTitle:"赶快用账号进行登录吧！",
								btnValue:"返回我的钱包",
								url:'/wallet/wallet'
							});
						}else{ 
							uni.showToast({
								title: res.data.list.msg,
								icon:'none'
							});
						}
					},  
					fail: () => {},  
					complete: () => {}  
				});
			}
		}
	}
}
</script>

<style lang="scss">
page{
	background:#f3f3f3;
}
</style>
<style lang="scss" scoped>
.price-item{
	width:250rpx;
	margin: 65rpx auto;
	.u-input__input{
		font-size:36rpx;
	}
}
.main{
	margin:18rpx 40rpx 0;
	.page-card{
		padding:20rpx 40rpx;
		border-radius: 20rpx;
		background: #fff;
		/deep/ .u-cell{
			padding:15rpx 0;
			.u-cell_title{
				font-size: 30rpx;
				color: #333;
			}
			&:last-child:after{
				border:none;
			}
		}
	}
	.btn{
		margin-top:70rpx;
		background:linear-gradient(to right,#eeb115,#c17306);
		color: #fff!important;
		border: none;
	}
}
</style>